#!/bin/bash

# These tests need Nodejs 22 (or later). See: [e2e_nodejs_old_v14]
#
node_ver=$(node --version)
if [[ "$node_ver" == v22.* ]]; then
  : # Correct version — run the tests.
elif [[ "$node_ver" == v14.* ]]; then
  echo "Skipping this test — it needs Nodejs v22, but now we're using $node_ver."
  exit 0
else
  echo "Totally unexpected Nodejs version. Is: $node_ver, should be v22 (or v14)."
  exit 1
fi

cd tests/e2e-wdio7/


# [E2EHTTPS]
# This is new Webdriver 7, since we're in tests/e2e-wdio7/.  [wdio_6_to_7]
cmd="node_modules/.bin/wdio  wdio.conf.ts  $@"
echo
echo "NODE_TLS_REJECT_UNAUTHORIZED=0  $cmd"
echo
NODE_TLS_REJECT_UNAUTHORIZED=0  $cmd
exit_code=$?

if [ $exit_code -ne 0 ]; then
  echo
  echo
  echo "Error. Webdriverio 7 E2E test failed, exit code: $exit_code"
  echo
  echo "Was started like so:"
  echo "    NODE_TLS_REJECT_UNAUTHORIZED=0  $cmd"
fi

echo
exit $exit_code
